home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00041_Script_Espalhamento < prev    next >
Text File  |  1999-03-19  |  2KB  |  68 lines

  1. on espalha num, maxX, maxY
  2.   set lista = []
  3.   repeat with i = 1 to num
  4.     add lista, point(random(maxX),random(maxY))
  5.   end repeat
  6.   repeat with z = 1 to 4
  7.     repeat with i = 1 to num
  8.       repeat with j = 1 to num
  9.         if i <> j then
  10.           set a = getAt(lista,i)
  11.           set b = getAt(lista,j)
  12.           set a = repele(a,b, maxX, maxY, power(2,z)*10000)
  13.           setAt(lista,i,a)
  14.         end if
  15.       end repeat
  16.     end repeat
  17.   end repeat
  18.   return lista
  19. end
  20.  
  21. on mediaLista lista
  22.   set soma = 0.0
  23.   repeat with i = 1 to count(lista)
  24.     repeat with j = 1 to count(lista)
  25.       if i <> j then 
  26.         set dx = float(the locH of getAt(lista,i) - the locH of getAt(lista,j))
  27.         set dy = float(the locV of getAt(lista,i) - the locV of getAt(lista,j))
  28.         set d = sqrt(dx*dx + dy*dy)
  29.         set soma = soma + 1.0 / d
  30.       end if
  31.     end repeat
  32.   end repeat
  33.   set soma = soma / ( count(lista) * (count(lista)-1) )
  34.   set soma = 1.0 / soma
  35.   return soma
  36. end
  37.  
  38. on repele a, b, maxX, maxY, forca
  39.   set x = the locH of a
  40.   set y = the locV of a
  41.   set dx = float(distancia (x, the locH of b, maxX))
  42.   if dx = 0.0 then set dx = random(2) * 2.0 - 3.0
  43.   set dy = float(distancia (y, the locV of b, maxY))
  44.   if dy = 0.0 then set dy = random(2) * 2.0 - 3.0
  45.   set dist = dx * dx + dy * dy
  46.   set new = sqrt(dist + forca)
  47.   set dist = sqrt(dist)
  48.   
  49.   set x = the locH of b + dx * new / dist
  50.   if x < 0 then set x = x + maxX
  51.   else if x >= maxX then set x = x - maxX
  52.   set y = the locV of b + dy * new / dist
  53.   if y < 0 then set y = y + maxY
  54.   else if y >= maxY then set y = y - maxY
  55.   return point(x,y)
  56. end
  57.  
  58. on distancia a, b, max
  59.   if a - b > max / 2 then
  60.     return a - (b + max)
  61.   else if a - b < - max / 2 then
  62.     return a + max - b
  63.   else
  64.     return a-b
  65.   end if
  66. end
  67.  
  68.